unit MPLARunSelect;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, Grids, ADODB, DBGrids;

type
  TdlgSelectRun = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    dbgRunAssays: TDBGrid;
    edtRunName: TEdit;
    btnAddNew: TButton;
    procedure btnAddNewClick(Sender: TObject);
    procedure dbgRunAssaysTitleClick(Column: TColumn);
  private
    { Private declarations }
  public
    { Public declarations }
    function SelectRun : integer;
  end;

var
  dlgSelectRun: TdlgSelectRun;

implementation

uses MLPAdm;

{$R *.DFM}

procedure TdlgSelectRun.btnAddNewClick(Sender: TObject);
begin
  if edtRunName.Text<>'' then
  begin
    DM.AddRun(edtRunName.Text);
    DM.qrySelectRun.Requery;
  end;
end;

procedure TdlgSelectRun.dbgRunAssaysTitleClick(Column: TColumn);
{$J+}
 const PreviousColumnIndex : integer = -1;
{$J-}
begin
  if dbgRunAssays.DataSource.DataSet is TCustomADODataSet then
  with TCustomADODataSet(dbgRunassays.DataSource.DataSet) do
  begin
    if (0<=PreviousColumnIndex) and (PreviousColumnIndex<dbgRunassays.Columns.Count) then
    begin
      dbgRunassays.Columns[PreviousColumnIndex].title.Font.Style :=
      dbgRunassays.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
    end;

    Column.title.Font.Style :=
    Column.title.Font.Style + [fsBold];
    PreviousColumnIndex := Column.Index;

    if (Pos(Column.Field.FieldName, string(Sort)) = 1)
    and (Pos(' DESC', string(Sort))= 0) then
      Sort := Column.Field.FieldName + ' DESC'
    else
      Sort := Column.Field.FieldName + ' ASC';
  end;
end;

function TdlgSelectRun.SelectRun: integer;
begin
  DM.qryRunAssays.Open;
  if ShowModal = mrOK then
  begin
    result:=DM.qrySelectRun.FieldValues['runid'];
  end
  else
    result:=-1;
end;

end.
